package com.cx.jvm;

import lombok.SneakyThrows;

/**
 * @Author: robert.song
 * @Date: Created in 2022/8/14
 */
public class JVM4_DeadLock {
    public static void main(String[] args) {
        Thread t1 = new Thread() {
            @SneakyThrows
            @Override
            public void run() {
                synchronized (this) {
                    Thread.sleep(2000);
                    synchronized (this.getClass()) {
                        while (true) {
                            System.out.println(Thread.currentThread().getName());
                        }
                    }
                }
            }
        };

        Thread t2 = new Thread() {
            public void run() {
                synchronized (this.getClass()) {
                    synchronized (this) {
                        while (true) {
                            System.out.println(Thread.currentThread().getName());
                        }
                    }
                }
            }
        };

        t1.start();
        t2.start();
    }
}
